package twoD.hofem;

/**
 * Utility class for Polynomial bases.
 * 
 * @author Matthias Baitsch
 */
public abstract class AbstractPolynomialBasisOnR implements PolynomialBasisOnR {

	private FunctionRToR[] basis_;

	/**
	 * Creates the shape functions for the given polynomial degree.
	 * 
	 * @param p
	 *            polynomial degree
	 * @return set of shape functions
	 */
	public abstract FunctionRToR[] createBasis(int p);

	public FunctionRToR getBasisFunction(int idx) {
		return basis_[idx];
	}

	public FunctionRToR[] getBasisFunctions() {
		return basis_;
	}

	public double[] getBreakpoints() {
		return null;
	}

	public int getDimension() {
		return basis_.length;
	}

	/**
	 * Returns a name for function basis, e.g. Lagrange.
	 * 
	 * @return name
	 */
	public abstract String getName();

	public int getP() {
		return getDimension() - 1;
	}

	public void setP(int p) {
		if (p < 1) {
			throw new IllegalArgumentException("p must be at least 1");
		}
		basis_ = createBasis(p);
	}

	@Override
	public String toString() {
		return getName();
	}
}
